package org.wu.framework.lazy.orm.core.source.adapter;

import org.wu.framework.lazy.orm.core.config.enums.LazyDataSourceType;
import org.wu.framework.lazy.orm.core.persistence.conf.*;
import org.wu.framework.lazy.orm.core.source.SqlSourceClass;
import org.wu.framework.lazy.orm.core.source.advanced.SourceAdvanced;
import org.wu.framework.lazy.orm.core.source.clickhouse.ClickHouseSourceAdvancedTarget;
import org.wu.framework.lazy.orm.core.source.h2.H2SourceAdvancedTarget;
import org.wu.framework.lazy.orm.core.source.mysql.MySQLSourceAdvancedTarget;
import org.wu.framework.lazy.orm.core.source.postgresql.PostgresSQLSourceAdvancedTarget;
import org.wu.framework.lazy.orm.core.source.questdb.QuestDBSourceAdvancedTarget;
import org.wu.framework.lazy.orm.core.source.sqlite.SqliteSourceAdvancedTarget;
import org.wu.framework.lazy.orm.core.toolkit.DynamicLazyDataSourceTypeHolder;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentMap;

/**
 * 数据源工厂处理器
 *
 * @see DynamicLazyDataSourceTypeHolder
 * @see MySQLSourceAdvancedTarget
 * @see ClickHouseSourceAdvancedTarget
 * @see PostgresSQLSourceAdvancedTarget
 * @see H2SourceAdvancedTarget
 * @see SqliteSourceAdvancedTarget
 */
public class SourceFactory {

    /**
     * 默认数据源，项目加载后会自动确定当前数据源
     */
    public static LazyDataSourceType defaultLazyDataSourceType = null;

    private static final List<SourceAdvanced> sourceAdvancedList = List.of(new MySQLSourceAdvancedTarget(),
            new ClickHouseSourceAdvancedTarget(),
            new PostgresSQLSourceAdvancedTarget(),
            new H2SourceAdvancedTarget(),
            new SqliteSourceAdvancedTarget(),
            new QuestDBSourceAdvancedTarget()
    );

    /**
     * 获取url
     *
     * @param host getHost
     * @param port 端口
     */
    public static String getUrl(LazyDataSourceType lazyDataSourceType, String host, int port) {
        return getUrl(lazyDataSourceType, host, port, null);
    }


    /**
     * 获取url
     *
     * @param host getHost
     * @param port 端口
     */
    public static String getUrl(LazyDataSourceType lazyDataSourceType, String host, int port, String schema) {
        for (SourceAdvanced sourceAdvanced : sourceAdvancedList) {
            if (sourceAdvanced.support(lazyDataSourceType)) {
                return sourceAdvanced.getUrl(host, port, schema);
            }
        }
        return null;
    }

    /**
     * 格式化url
     *
     * @param url url
     *
     */
    public static String formatUrl(String url) {
        LazyDataSourceType lazyDataSourceType = getLazyDataSourceType(url);
        for (SourceAdvanced sourceAdvanced : sourceAdvancedList) {
            if (sourceAdvanced.support(lazyDataSourceType)) {
                return sourceAdvanced.formatUrl(url);
            }
        }
        return null;
    }

    /**
     * 通过url获取 url中的 host 有可能是空
     *
     * @param url url
     */
    public static String getHost(String url) {
        LazyDataSourceType lazyDataSourceType = getLazyDataSourceType(url);
        for (SourceAdvanced sourceAdvanced : sourceAdvancedList) {
            if (sourceAdvanced.support(lazyDataSourceType)) {
                return sourceAdvanced.getHost(url);
            }
        }
        return null;
    }

    /**
     * 通过url获取 url中的 port 有可能是空
     *
     * @param url url
     */
    public static int getPort(String url) {
        LazyDataSourceType lazyDataSourceType = getLazyDataSourceType(url);
        for (SourceAdvanced sourceAdvanced : sourceAdvancedList) {
            if (sourceAdvanced.support(lazyDataSourceType)) {
                return sourceAdvanced.getPort(url);
            }
        }
        return 0;
    }

    /**
     * 通过url获取 url中的schema
     *
     * @param url url
     * @return url中的schema
     */
    public static String getUrlSchema(String url) {
        LazyDataSourceType dataSourceType = getLazyDataSourceType(url);
        for (SourceAdvanced sourceAdvanced : sourceAdvancedList) {
            if (sourceAdvanced.support(dataSourceType)) {

                return sourceAdvanced.getUrlSchema(url);
            }
        }
        throw new IllegalArgumentException("无法解析url中的schema:[" + url + "]");
    }

    /**
     * 通过url 获取 数据源类型
     *
     * @param url 数据库连接url
     * @return 数据源类型
     */
    public static LazyDataSourceType getLazyDataSourceType(String url) {
        for (SourceAdvanced sourceAdvanced : sourceAdvancedList) {
            LazyDataSourceType dataSourceType = sourceAdvanced.getLazyDataSourceType(url);
            if (null != dataSourceType) {
                return dataSourceType;
            }
        }
        throw new IllegalArgumentException("无法解析url为指定类型的数据源类型:[" + url + "]");
    }

    /**
     * 获取 information_schema
     *
     * @param url 连接url
     * @return 返回 information_schema 的url连接地址
     */
    public static String getDefaultInformationSchemaUrl(String url) {
        LazyDataSourceType lazyDataSourceType = getLazyDataSourceType(url);
        for (SourceAdvanced sourceAdvanced : sourceAdvancedList) {
            if (sourceAdvanced.support(lazyDataSourceType)) {
                return sourceAdvanced.getDefaultInformationSchemaUrl(url);
            }
        }
        throw new IllegalArgumentException("无法从url中解析出information_schema:[" + url + "]");
    }


//    #########################################################################################################################################################################################
//    Java class 解析成表结构 开始
//    #########################################################################################################################################################################################


    /**
     * 获取表结构
     *
     * @param lazyDataSourceType 数据源类型
     * @param lazyColumnList     字段信息
     * @return 表结构
     */
    public static LazyTableEndpoint<?> analyzeLazyTableFromLazyColumns(LazyDataSourceType lazyDataSourceType,
                                                                    LazyTableInfo lazyTableInfo,
                                                                    List<? extends LazyColumn> lazyColumnList) {
        for (SourceAdvanced sourceAdvanced : sourceAdvancedList) {
            if (sourceAdvanced.support(lazyDataSourceType)) {
                return sourceAdvanced.analyzeLazyTableFromLazyColumns(lazyTableInfo,lazyColumnList);
            }
        }
        throw new IllegalArgumentException("不支持数据源类型:" + lazyDataSourceType);
    }

    /**
     * 根据当前上下文获取数据源类型而后解析出表结构
     *
     * @param lazyTableInfo 表结构信息
     * @param lazyColumnList  表字段信息
     * @return 表结构
     * @see SqlSourceClass#getInstance(Class)
     */
    public static LazyTableEndpoint<?> defaultAnalyzeLazyTableFromLazyColumns(LazyTableInfo lazyTableInfo,
                                                                           List<? extends LazyColumn> lazyColumnList) {
        // 上下文获取 数据源类型
        LazyDataSourceType currentLazyDataSourceType = DynamicLazyDataSourceTypeHolder.peek() == null ? defaultLazyDataSourceType : DynamicLazyDataSourceTypeHolder.peek();
        if (currentLazyDataSourceType == null) {
            throw new IllegalArgumentException("无法解析当前数据源类型");
        }
        return analyzeLazyTableFromLazyColumns(currentLazyDataSourceType,lazyTableInfo, lazyColumnList);
    }

    /**
     * 获取表结构
     *
     * @param lazyDataSourceType 数据源类型
     * @param clazz              需要解析的class
     * @return 表结构
     */
    public static LazyTableEndpoint<?> analyzeLazyTableFromClass(LazyDataSourceType lazyDataSourceType, Class<?> clazz) {
        for (SourceAdvanced sourceAdvanced : sourceAdvancedList) {
            if (sourceAdvanced.support(lazyDataSourceType)) {
                return sourceAdvanced.analyzeLazyTableFromClass(clazz);
            }
        }
        throw new IllegalArgumentException("不支持数据源类型:" + lazyDataSourceType);
    }

    /**
     * 根据当前上下文获取数据源类型而后解析出表结构
     *
     * @param clazz 需要解析的class
     * @return 表结构
     * @see SqlSourceClass#getInstance(Class)
     */
    public static LazyTableEndpoint<?> defaultAnalyzeLazyTableFromClass(Class<?> clazz) {
        // 上下文获取 数据源类型
        LazyDataSourceType currentLazyDataSourceType = DynamicLazyDataSourceTypeHolder.peek() == null ? defaultLazyDataSourceType : DynamicLazyDataSourceTypeHolder.peek();
        if (currentLazyDataSourceType == null) {
            throw new IllegalArgumentException("无法解析当前数据源类型");
        }
        return analyzeLazyTableFromClass(currentLazyDataSourceType, clazz);
    }

    /**
     * 获取表结构
     * 因为是map格式所以缓存
     *
     * @param lazyDataSourceType 数据源类型
     * @param beanData           需要解析的beanData
     * @return 表结构
     */
    public static LazyTableEndpoint<?> analyzeLazyTableFromMap(LazyDataSourceType lazyDataSourceType,String schemaName, String tableName, Map<String, Object> beanData) {
        for (SourceAdvanced sourceAdvanced : sourceAdvancedList) {
            if (sourceAdvanced.support(lazyDataSourceType)) {
                return sourceAdvanced.analyzeLazyTableFromMap(schemaName, tableName, beanData);
            }
        }
        throw new IllegalArgumentException("不支持数据源类型:" + lazyDataSourceType);
    }

    /**
     * 根据当前上下文获取数据源类型而后解析出表结构
     * 因为是map格式所以缓存
     *
     * @param beanData 需要解析的beanData
     * @param tableName 表名称
     * @param schemaName 数据库名称
     * @return 表结构
     */
    public static LazyTableEndpoint defaultAnalyzeLazyTableFromMap(String schemaName,String tableName, Map<String, Object> beanData) {
        // 上下文获取 数据源类型
        LazyDataSourceType currentLazyDataSourceType = DynamicLazyDataSourceTypeHolder.peek() == null ? defaultLazyDataSourceType : DynamicLazyDataSourceTypeHolder.peek();
        if (currentLazyDataSourceType == null) {
            throw new IllegalArgumentException("无法解析当前数据源类型");
        }
        return analyzeLazyTableFromMap(currentLazyDataSourceType,schemaName, tableName, beanData);
    }
    /**
     * 根据当前上下文获取数据源类型而后解析出表结构
     *
     * 因为是map格式所以缓存
     * @param tableName  表名称
     * @param beanData 需要解析的beanData
     * @return 表结构
     */
    public static LazyTableEndpoint defaultAnalyzeLazyTableFromMap(String tableName, Map<String, Object> beanData) {
        // 上下文获取 数据源类型
        LazyDataSourceType currentLazyDataSourceType = DynamicLazyDataSourceTypeHolder.peek() == null ? defaultLazyDataSourceType : DynamicLazyDataSourceTypeHolder.peek();
        if (currentLazyDataSourceType == null) {
            throw new IllegalArgumentException("无法解析当前数据源类型");
        }
        return analyzeLazyTableFromMap(currentLazyDataSourceType,null, tableName, beanData);
    }


    /**
     * 获取表字段信息实例
     *
     * @param lazyDataSourceType 数据源类型
     * @return 表结构
     */
    public static LazyTableFieldEndpoint getLazyTableFieldEndpointInstance(LazyDataSourceType lazyDataSourceType) {
        for (SourceAdvanced sourceAdvanced : sourceAdvancedList) {
            if (sourceAdvanced.support(lazyDataSourceType)) {
                return sourceAdvanced.getLazyTableFieldEndpointInstance();
            }
        }
        throw new IllegalArgumentException("不支持数据源类型:" + lazyDataSourceType);
    }

    /**
     * 根据当前上下文 表字段信息实例
     *
     * @return 表结构
     */
    public static LazyTableFieldEndpoint getDefaultLazyTableFieldEndpointInstance() {
        // 上下文获取 数据源类型
        LazyDataSourceType currentLazyDataSourceType = DynamicLazyDataSourceTypeHolder.peek() == null ? defaultLazyDataSourceType : DynamicLazyDataSourceTypeHolder.peek();
        if (currentLazyDataSourceType == null) {
            throw new IllegalArgumentException("无法解析当前数据源类型");
        }
        return getLazyTableFieldEndpointInstance(currentLazyDataSourceType);
    }


    /**
     * 获取数据库表实例
     *
     * @param lazyDataSourceType 数据源类型
     * @return 表结构
     */
    public static  LazyTableEndpoint<?>  getLazyLazyTableEndpointInstance(LazyDataSourceType lazyDataSourceType) {
        for (SourceAdvanced sourceAdvanced : sourceAdvancedList) {
            if (sourceAdvanced.support(lazyDataSourceType)) {
                return sourceAdvanced.getLazyTableEndpointInstance();
            }
        }
        throw new IllegalArgumentException("不支持数据源类型:" + lazyDataSourceType);
    }

    /**
     * 根据当前上下文 获取数据库表实例
     *
     * @return 表结构
     */
    public static  LazyTableEndpoint<?>  getDefaultLazyTableEndpointInstance() {
        // 上下文获取 数据源类型
        LazyDataSourceType currentLazyDataSourceType = DynamicLazyDataSourceTypeHolder.peek() == null ? defaultLazyDataSourceType : DynamicLazyDataSourceTypeHolder.peek();
        if (currentLazyDataSourceType == null) {
            throw new IllegalArgumentException("无法解析当前数据源类型");
        }
        return getLazyLazyTableEndpointInstance(currentLazyDataSourceType);
    }

    /**
     * 获取当前数据类型缓存的表结构
     *
     * @param lazyDataSourceType 数据源类型
     * @return 当前数据类型缓存的表结构
     */
    public static ConcurrentMap<Class<?>,  LazyTableEndpoint<?> > getClassTableCache(LazyDataSourceType lazyDataSourceType) {
        for (SourceAdvanced sourceAdvanced : sourceAdvancedList) {
            if (sourceAdvanced.support(lazyDataSourceType)) {
                return sourceAdvanced.getClassTableCache();
            }
        }
        throw new IllegalArgumentException("不支持数据源类型:" + lazyDataSourceType);
    }

    /**
     * 获取当前数据类型缓存的表结构
     *
     * @return 当前数据类型缓存的表结构
     */
    public static ConcurrentMap<Class<?>,  LazyTableEndpoint<?> > getClassTableCache() {
        // 上下文获取 数据源类型
        LazyDataSourceType currentLazyDataSourceType = DynamicLazyDataSourceTypeHolder.peek() == null ? defaultLazyDataSourceType : DynamicLazyDataSourceTypeHolder.peek();
        if (currentLazyDataSourceType == null) {
            throw new IllegalArgumentException("无法解析当前数据源类型");
        }
        return getClassTableCache(currentLazyDataSourceType);
    }

    /**
     * 获取当前数据类型缓存的表结构
     *
     * @param lazyDataSourceType 数据源类型
     * @return 当前数据类型缓存的表结构
     */
    public static ConcurrentMap<String,  LazyTableEndpoint<?> > getMapTableCache(LazyDataSourceType lazyDataSourceType) {
        for (SourceAdvanced sourceAdvanced : sourceAdvancedList) {
            if (sourceAdvanced.support(lazyDataSourceType)) {
                return sourceAdvanced.getMapTableCache();
            }
        }
        throw new IllegalArgumentException("不支持数据源类型:" + lazyDataSourceType);
    }

    /**
     * 获取当前数据类型缓存的表结构
     *
     * @return 当前数据类型缓存的表结构
     */
    public static ConcurrentMap<String,  LazyTableEndpoint<?> > getMapTableCache() {
        // 上下文获取 数据源类型
        LazyDataSourceType currentLazyDataSourceType = DynamicLazyDataSourceTypeHolder.peek() == null ? defaultLazyDataSourceType : DynamicLazyDataSourceTypeHolder.peek();
        if (currentLazyDataSourceType == null) {
            throw new IllegalArgumentException("无法解析当前数据源类型");
        }
        return getMapTableCache(currentLazyDataSourceType);
    }

    /**
     * 关键字转译
     *
     * @param column 数据库字段
     * @return 转译后关键字
     */
    public static String cleanSpecialColumn(String column) {
        // 上下文获取 数据源类型
        LazyDataSourceType currentLazyDataSourceType = DynamicLazyDataSourceTypeHolder.peek() == null ? defaultLazyDataSourceType : DynamicLazyDataSourceTypeHolder.peek();
        if (currentLazyDataSourceType == null) {
            throw new IllegalArgumentException("无法解析当前数据源类型");
        }
        return cleanSpecialColumn(currentLazyDataSourceType, column);
    }

    /**
     * 关键字转译
     *
     * @param column             数据库字段
     * @param lazyDataSourceType 数据库类型
     * @return 转译后关键字
     */
    public static String cleanSpecialColumn(LazyDataSourceType lazyDataSourceType, String column) {
        for (SourceAdvanced sourceAdvanced : sourceAdvancedList) {
            if (sourceAdvanced.support(lazyDataSourceType)) {
                return sourceAdvanced.cleanSpecialColumn(column);
            }
        }
        throw new IllegalArgumentException("不支持数据源类型:" + lazyDataSourceType);
    }


//    #########################################################################################################################################################################################
//    Java class 解析成表结构 结束
//    #########################################################################################################################################################################################


//    #########################################################################################################################################################################################
//    Java class 获取数据库表、字段、索引sql 开始
//    #########################################################################################################################################################################################

    /**
     * 获取 创建 database语句
     *
     * @param schemaName schema 名称
     * @return 创建 database语句
     */
    public static String createSchemaSql(String schemaName) {
        // 上下文获取 数据源类型
        LazyDataSourceType currentLazyDataSourceType = DynamicLazyDataSourceTypeHolder.peek() == null ? defaultLazyDataSourceType : DynamicLazyDataSourceTypeHolder.peek();
        if (currentLazyDataSourceType == null) {
            throw new IllegalArgumentException("无法解析当前数据源类型");
        }
        return createSchemaSql(currentLazyDataSourceType, schemaName);
    }

    /**
     * 获取 创建 database语句
     *
     * @param schemaName         schema 名称
     * @param lazyDataSourceType 数据源类型
     * @return 创建 database语句
     */
    public static String createSchemaSql(LazyDataSourceType lazyDataSourceType, String schemaName) {
        for (SourceAdvanced sourceAdvanced : sourceAdvancedList) {
            if (sourceAdvanced.support(lazyDataSourceType)) {
                return sourceAdvanced.createSchemaSql(schemaName);
            }
        }
        throw new IllegalArgumentException("不支持数据源类型:" + lazyDataSourceType);
    }

    /**
     * 获取数据库schema
     *
     * @return 数据库schema
     */
    public static String findSchemaListSql() {
        // 上下文获取 数据源类型
        LazyDataSourceType currentLazyDataSourceType = DynamicLazyDataSourceTypeHolder.peek() == null ? defaultLazyDataSourceType : DynamicLazyDataSourceTypeHolder.peek();
        if (currentLazyDataSourceType == null) {
            throw new IllegalArgumentException("无法解析当前数据源类型");
        }
        return findSchemaListSql(currentLazyDataSourceType);
    }

    /**
     * 获取数据库schema
     *
     * @param lazyDataSourceType 数据库类型
     * @return 数据库schema
     */
    public static String findSchemaListSql(LazyDataSourceType lazyDataSourceType) {
        for (SourceAdvanced sourceAdvanced : sourceAdvancedList) {
            if (sourceAdvanced.support(lazyDataSourceType)) {
                return sourceAdvanced.findSchemaListSql();
            }
        }
        throw new IllegalArgumentException("不支持数据源类型:" + lazyDataSourceType);
    }

    /**
     * 查询原始表字段sql
     *
     * @param schema 数据库
     * @param table  表
     * @return 查询原始表字段sql
     */
    public static String findTableColumnListSql(String schema, String table) {
        // 上下文获取 数据源类型
        LazyDataSourceType currentLazyDataSourceType = DynamicLazyDataSourceTypeHolder.peek() == null ? defaultLazyDataSourceType : DynamicLazyDataSourceTypeHolder.peek();
        if (currentLazyDataSourceType == null) {
            throw new IllegalArgumentException("无法解析当前数据源类型");
        }
        return findTableColumnListSql(currentLazyDataSourceType, schema, table);
    }

    /**
     * 查询原始表字段sql
     *
     * @param schema             数据库
     * @param table              表
     * @param lazyDataSourceType 数据库类型
     * @return 查询原始表字段sql
     */
    public static String findTableColumnListSql(LazyDataSourceType lazyDataSourceType, String schema, String table) {
        for (SourceAdvanced sourceAdvanced : sourceAdvancedList) {
            if (sourceAdvanced.support(lazyDataSourceType)) {
                return sourceAdvanced.findTableColumnListSql(schema, table);
            }
        }
        throw new IllegalArgumentException("不支持数据源类型:" + lazyDataSourceType);
    }

    /**
     * 查询索引sql
     *
     * @param schema 数据库
     * @param table  表
     * @return 查询索引sql
     */
    public static String findTableColumnIndexListSql(String schema, String table) {
        // 上下文获取 数据源类型
        LazyDataSourceType currentLazyDataSourceType = DynamicLazyDataSourceTypeHolder.peek() == null ? defaultLazyDataSourceType : DynamicLazyDataSourceTypeHolder.peek();
        if (currentLazyDataSourceType == null) {
            throw new IllegalArgumentException("无法解析当前数据源类型");
        }
        return findTableColumnIndexListSql(currentLazyDataSourceType, schema, table);
    }

    /**
     * 查询索引sql
     *
     * @param schema             数据库
     * @param table              表
     * @param lazyDataSourceType 数据库类型
     * @return 查询索引sql
     */
    public static String findTableColumnIndexListSql(LazyDataSourceType lazyDataSourceType, String schema, String table) {
        for (SourceAdvanced sourceAdvanced : sourceAdvancedList) {
            if (sourceAdvanced.support(lazyDataSourceType)) {
                return sourceAdvanced.findTableColumnIndexListSql(schema, table);
            }
        }
        throw new IllegalArgumentException("不支持数据源类型:" + lazyDataSourceType);
    }


    /**
     * 查询表信息 sql
     *
     * @param schema 数据库
     * @param table  表
     * @return 查询表信息sql
     */
    public static String findTableInfoSql(String schema, String table) {
        // 上下文获取 数据源类型
        LazyDataSourceType currentLazyDataSourceType = DynamicLazyDataSourceTypeHolder.peek() == null ? defaultLazyDataSourceType : DynamicLazyDataSourceTypeHolder.peek();
        if (currentLazyDataSourceType == null) {
            throw new IllegalArgumentException("无法解析当前数据源类型");
        }
        return findTableInfoSql(currentLazyDataSourceType, schema, table);
    }

    /**
     * 查询表信息sql
     *
     * @param schema             数据库
     * @param table              表
     * @param lazyDataSourceType 数据库类型
     * @return 查询表信息sql
     */
    public static String findTableInfoSql(LazyDataSourceType lazyDataSourceType, String schema, String table) {
        for (SourceAdvanced sourceAdvanced : sourceAdvancedList) {
            if (sourceAdvanced.support(lazyDataSourceType)) {
                return sourceAdvanced.findTableInfoSql(schema, table);
            }
        }
        throw new IllegalArgumentException("不支持数据源类型:" + lazyDataSourceType);
    }



//    #########################################################################################################################################################################################
//    Java class 获取数据库表、字段、索引sql 结束
//    #########################################################################################################################################################################################

//    #########################################################################################################################################################################################
//    根据不同数据源获取不同对象的类型 开始
//    #########################################################################################################################################################################################

    /**
     * 获取指定类型数据源对应的表信息
     *
     * @return 获取使用的表结构对应的class
     */
    public static Class<? extends LazyTableInfo> findTableInfoClass() {
        // 上下文获取 数据源类型
        LazyDataSourceType currentLazyDataSourceType = DynamicLazyDataSourceTypeHolder.peek() == null ? defaultLazyDataSourceType : DynamicLazyDataSourceTypeHolder.peek();
        if (currentLazyDataSourceType == null) {
            throw new IllegalArgumentException("无法解析当前数据源类型");
        }
        return findTableInfoClass(currentLazyDataSourceType);
    }

    /**
     * 获取指定类型数据源对应的表信息
     *
     * @param lazyDataSourceType 数据库类型
     * @return 获取使用的表结构对应的class
     */
    public static Class<? extends LazyTableInfo> findTableInfoClass(LazyDataSourceType lazyDataSourceType) {
        for (SourceAdvanced sourceAdvanced : sourceAdvancedList) {
            if (sourceAdvanced.support(lazyDataSourceType)) {
                return sourceAdvanced.findTableInfoClass();
            }
        }
        throw new IllegalArgumentException("不支持数据源类型:" + lazyDataSourceType);
    }

    /**
     * 获取指定类型数据源对应的表信息
     *
     * @return 获取使用的数据库结构对应的class
     */
    public static Class<? extends LazySchemata> findSchemaInfoClass() {
        // 上下文获取 数据源类型
        LazyDataSourceType currentLazyDataSourceType = DynamicLazyDataSourceTypeHolder.peek() == null ? defaultLazyDataSourceType : DynamicLazyDataSourceTypeHolder.peek();
        if (currentLazyDataSourceType == null) {
            throw new IllegalArgumentException("无法解析当前数据源类型");
        }
        return findSchemaInfoClass(currentLazyDataSourceType);
    }

    /**
     * 获取指定类型数据源对应的表信息
     *
     * @param lazyDataSourceType 数据库类型
     * @return 获取使用的数据库结构对应的class
     */
    public static Class<? extends LazySchemata> findSchemaInfoClass(LazyDataSourceType lazyDataSourceType) {
        for (SourceAdvanced sourceAdvanced : sourceAdvancedList) {
            if (sourceAdvanced.support(lazyDataSourceType)) {
                return sourceAdvanced.findSchemaInfoClass();
            }
        }
        throw new IllegalArgumentException("不支持数据源类型:" + lazyDataSourceType);
    }

    /**
     * 获取使用的字段结构对应的class
     *
     * @return 获取使用的字段结构对应的class
     */
    public static Class<? extends LazyColumn> findColumnInfoClass() {
        // 上下文获取 数据源类型
        LazyDataSourceType currentLazyDataSourceType = DynamicLazyDataSourceTypeHolder.peek() == null ? defaultLazyDataSourceType : DynamicLazyDataSourceTypeHolder.peek();
        if (currentLazyDataSourceType == null) {
            throw new IllegalArgumentException("无法解析当前数据源类型");
        }
        return findColumnInfoClass(currentLazyDataSourceType);
    }

    /**
     * 获取使用的字段结构对应的class
     *
     * @param lazyDataSourceType 数据库类型
     * @return 获取使用的字段结构对应的class
     */
    public static Class<? extends LazyColumn> findColumnInfoClass(LazyDataSourceType lazyDataSourceType) {
        for (SourceAdvanced sourceAdvanced : sourceAdvancedList) {
            if (sourceAdvanced.support(lazyDataSourceType)) {
                return sourceAdvanced.findColumnInfoClass();
            }
        }
        throw new IllegalArgumentException("不支持数据源类型:" + lazyDataSourceType);
    }

    /**
     * 获取字段索引对应的class结构
     *
     * @return 获取字段索引对应的class结构
     */
    public static Class<? extends LazyColumnIndex> findColumnIndexInfoClass() {
        // 上下文获取 数据源类型
        LazyDataSourceType currentLazyDataSourceType = DynamicLazyDataSourceTypeHolder.peek() == null ? defaultLazyDataSourceType : DynamicLazyDataSourceTypeHolder.peek();
        if (currentLazyDataSourceType == null) {
            throw new IllegalArgumentException("无法解析当前数据源类型");
        }
        return findColumnIndexInfoClass(currentLazyDataSourceType);
    }

    /**
     * 获取字段索引对应的class结构
     *
     * @param lazyDataSourceType 数据库类型
     * @return 获取字段索引对应的class结构
     */
    public static Class<? extends LazyColumnIndex> findColumnIndexInfoClass(LazyDataSourceType lazyDataSourceType) {
        for (SourceAdvanced sourceAdvanced : sourceAdvancedList) {
            if (sourceAdvanced.support(lazyDataSourceType)) {
                return sourceAdvanced.findColumnIndexInfoClass();
            }
        }
        throw new IllegalArgumentException("不支持数据源类型:" + lazyDataSourceType);
    }


//    #########################################################################################################################################################################################
//    根据不同数据源获取不同对象的类型 结束
//    #########################################################################################################################################################################################

}
